#pragma once
#include "../Include/igsensor.h"

// Code changed from Scott Seligman and KriX
// ---- HTC Touch Diamond sensor --------------------------------------------
// ------- by Scott Seligman <scott@scottandmichelle.net> -------------------
// ------- GESTURE_TOUCH related information from KriX <kriix@hotmail.com> --

typedef struct _SENSORDATA
{
    SHORT   TiltX;          // From -1000 to 1000 (about), 0 is flat
    SHORT   TiltY;          // From -1000 to 1000 (about), 0 is flat
    SHORT   Orientation;    // From -1000 to 1000 (about)
                        // 0 = Straight up, -1000 = Flat, 1000 = Upside down
    WORD    Unknown1;       // Always zero
    DWORD   AngleY;         // From 0 to 359
    DWORD   AngleX;         // From 0 to 359
    DWORD   Unknown2;       // Bit field?
} SENSORDATA, *PSENSORDATA;

enum HTCSensorType
{
    HTC_Something = 0,
    HTC_GSensor = 1,
    HTC_Light = 2,
    HTC_Another = 3,
};

class HTCGSensor :
	public IGSensor
{
public:
	HTCGSensor(void);
	~HTCGSensor(void);

	static HTCGSensor* Create();

private:
	// The following PInvokes were ported from the results of the reverse engineering done
    // by Scott at scottandmichelle.net.
    // Blog post: http://scottandmichelle.net/scott/comments.html?entry=784
	typedef HANDLE (WINAPI * PFN_HTCSensorOpen)(DWORD);
	typedef void (WINAPI * PFN_HTCSensorClose)(HANDLE);
	typedef DWORD (WINAPI * PFN_HTCSensorGetDataOutput)(HANDLE, PSENSORDATA);

	PFN_HTCSensorOpen           pfnHTCSensorOpen;
	PFN_HTCSensorClose          pfnHTCSensorClose;
	PFN_HTCSensorGetDataOutput  pfnHTCSensorGetDataOutput;
	
	HANDLE sensorHandle;

public:
	GVector GetGVector() override;
	void Register() override;
	void Unregister() override;

	void Process() override;

};
